<?php
require('setup.inc.php');
require(constant('SYSROOT') . 'points_payperiod.c.php');

$points = new PointsPayPeriod();
if (isset($_POST['submit'])) {
	$points->setEnteredBy($_SESSION['driver_id']);
	$points->getData();
	$validate = $points->validateData();
	if ($validate) $points->insertData();
}
?>

<style type="text/css">
div, table, select, option, input {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}

.error {
	color: #FF0000;
	margin-bottom: 20px;
	background-color: #FFCCCC;
	border: 1px solid #FF3333;
}
</style>

<script type="text/javascript">
function totalDriverPoints(id){
	single = document.forms[0].elements['points[' + id + ']'].value;
	double = document.forms[0].elements['doublePoints[' + id + ']'].value;
	triple = document.forms[0].elements['triplePoints[' + id + ']'].value;
	quadruple = document.forms[0].elements['quadruplePoints[' + id + ']'].value;
	
	trId = "row" + id;
	
	if (isNaN(single) || isNaN(double) || isNaN(triple) || isNaN(quadruple)){
		document.getElementById(trId).style.backgroundColor = "FFCCCC";
	} else {
		document.getElementById(trId).style.backgroundColor = "FFFFFF";
	}
	
	if (!(single == "" && double == "" && triple == "" && quadruple == "")){
		if (!isNaN(single) && single != "") single = single * 1;
		else single = 0;
	
		if (!isNaN(double) && double != "") double = 2 * double;
		else double = 0;
		
		if (!isNaN(triple) && triple != "") triple = 3 * triple;
		else triple = 0;
		
		if (!isNaN(quadruple) && quadruple != "") quadruple = 4 * quadruple;
		else quadruple = 0;

		totalPoints = (single + double + triple + quadruple);
		spanID = "totalPoints" + id;

		document.getElementById(spanID).innerHTML = totalPoints;
	}
}
</script>

<center>
<?
if ($validate){
?>
<div>
The pay period data has successfully been entered into the database. You may now do one of the following:<br /><br />
<a href="">Generate a seniority list</a><br />
<a href="">Add points for write ups/happy write ups</a><br />
<a href="">View recently added points</a><br />
</div>
<?
} else {
?>
<form action="points_payperiod.php" method="post">

<div style="padding-bottom: 20px">Pay Period Ending <? $points->displayPayPeriod(); ?></div>

<?
if ($points->getErrors()){
print_r($points->getErrors());
?>
<div class="error">There is an error in some of the data entered.<br />Please see the red fields below.</div> 
<?
}
?>

<div>
<table border="0" cellspacing="0" cellpadding="2">
<tr>
	<th>Driver</th>
	<th>Points</th>
	<th>Double<br />Points</th>
	<th>Triple<br />Points</th>
	<th>Quad<br />Points</th>
	<th>Total<br />Points</th>
</tr>
<? $points->displayActiveDriverForm(); ?>
</table>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<?
}
?>
</center>